import boardTpl from './tpl/board.tpl';
import itemTpl from './tpl/item.tpl';
import './index.scss';
import tools from '../../utils/tools';

class ShowBoard{
    constructor(el,phoneDatas){
        this.name = "showboard";
        this.phoneDatas = phoneDatas;
        this.$el = el;
      
    }
    init(){
        this.render();
    }
    render(){
        this.$el.append(tools.tplReplace(boardTpl(),{
           list:this.makeList(this.phoneDatas)
        }));
    }
    makeList(datas){
        var list = "";
           datas.forEach((item,idx)=>{
              list += tools.tplReplace(itemTpl(),{
                  id:item.id,
                  isFirst: idx % 5 === 0 ? 'first' : '',
                  pic:$.parseJSON(item.pics)[0][0][0],
                  phone_name:item.phone_name,
                  slogan:item.slogan.substring(1,10),
                  default_price:item.default_price
              })
          })
          return list;
    }
}

export{ ShowBoard }